package com.ebelter.bodyfatscale.ui.activity;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;

import com.ebelter.bodyfatscale.R;
import com.ebelter.bodyfatscale.common.Constants;
import com.ebelter.bodyfatscale.util.UserSpUtil;
import com.ebelter.btlibrary.util.SpUtil;
import com.ebelter.btlibrary.util.ULog;

import butterknife.OnClick;

/**
 * 启动页
 */

public class SplashActivity extends BaseActivity{

    private static final String TAG = "SplashActivity";

    @Override
    protected int loadLayoutById() {
        return R.layout.activity_splash;
    }

    @Override
    protected void initViews() {
    }

    @Override
    protected void initData() {
       Constants.isKgUnit= SpUtil.readBoolean(Constants.IUser.IS_KG_MODEL,true);
      // Constants.isKgUnit = false;

        boolean firstInto= SpUtil.readBoolean(Constants.IUser.FIRST_INTO,true);
        long user_id = UserSpUtil.readLong(Constants.IUser.USER_ID,-1);
        String nick_name = UserSpUtil.readString(Constants.IUser.NICK_NAME);
        String btid = UserSpUtil.readString(Constants.IUser.BT_ID);

        ULog.i(TAG,"----splash---A " + user_id);
        if (user_id>0&&!TextUtils.isEmpty(nick_name)&&!TextUtils.isEmpty(btid)){
            //说明已经登录了 直接登录吧
            startActivity(MainActivity.class);
            finish();
            return;
        }
        if (!firstInto){
            startActivity(new Intent(this, LoginActivity.class));
            finish();
            return;
        }
       // SpUtil.writeBoolean(Constants.IUser.FIRST_INTO,false);

    }

    @OnClick({ R.id.btn_sign_splash, R.id.btn_join_splash})
    public void btClick(View view){
        switch (view.getId()){
            case R.id.btn_sign_splash://sign_in 注册
                startActivity(new Intent(this, LoginActivity.class));
                break;
            case R.id.btn_join_splash://Join us free 登录
                startActivity(new Intent(this, RegisterActivity.class));
                break;

        }
    }
}
